package controllor

import (
	"fitness/internal/service"
	"fitness/pkg/middleware"
	"github.com/gin-gonic/gin"
)

type MenuController struct {
	MenuService *service.MenuService
	Rbac        *middleware.Rbac
}

func NewMenuController(menuService *service.MenuService, rbac *middleware.Rbac) *MenuController {
	return &MenuController{
		MenuService: menuService,
		Rbac:        rbac,
	}
}

func (menuApi *MenuController) InitApiRouter(engine *gin.Engine) {
	menu := engine.Group("/menus")
	{
		//获取菜单
		menu.GET("", middleware.Jwt, menuApi.MenuService.GetMenus)
		//获取路由
		menu.GET("/routes", middleware.Jwt, menuApi.MenuService.RoutesV1)
		//菜单下拉列表
		menu.GET("/options", middleware.Jwt, menuApi.MenuService.ListMenuOptions)
		//查找
		menu.GET("/:menuId/form", middleware.Jwt, menuApi.MenuService.GetMenuForm)
		//编辑
		menu.PUT("/:id", middleware.Jwt, menuApi.Rbac.RbacAuth("sys:menu:edit"), menuApi.MenuService.UpdateMenu)
		//新增菜单
		menu.POST("", middleware.Jwt, menuApi.Rbac.RbacAuth("sys:menu:add"), menuApi.MenuService.UpdateMenu)
		//删除
		menu.DELETE("/:id", middleware.Jwt, menuApi.Rbac.RbacAuth("sys:menu:delete"), menuApi.MenuService.DeleteMenu)
	}
}
